package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.net.userService
import com.polaris.live.resp.base.ListResp
import com.polaris.live.widget.refresh.OnListListener

/**
 * 粉丝
 *
 * @author Created by 长空 on 2023/11/16 09:15
 * @since 1.0.0
 */
open class GiveViewModel : BaseViewModel(), OnListListener {

    val followersLiveData = MutableLiveData<ResultState<ListResp<UserBasicVo>>>()

    val pageSize = 20  // 每页记录数

    private var searchText: String? = null
    private fun getFollowers(pageNumber: Int, pageSize: Int = this.pageSize) {
        request({ userService.getFollowers(searchText, pageNumber, pageSize) }, followersLiveData)
    }

    fun searchAgency(searchText: String?) {
        this.searchText = searchText
        getFollowers(pageNumber = 0)
    }

    override fun onRefresh() {
        getFollowers(pageNumber = 0)
    }

    override fun onLoadMore(pageIndex: Int) {
        getFollowers(pageNumber = pageIndex)
    }


}